package com.wbdgj.ui.booking;

import android.Manifest;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.google.gson.internal.LinkedTreeMap;
import com.igexin.sdk.PushManager;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.wbdgj.R;
import com.wbdgj.adapter.RoomAdapter;
import com.wbdgj.adapter.RoomHourAdapter;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.base.BaseFragment;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnNoResponseListener;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.ui.branch.BranchDetailActivity;
import com.wbdgj.ui.home.MapDialogAtivity;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.utils.ContextUtils;
import com.wbdgj.utils.ListViewForScrollView;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;
import com.wbdgj.utils.dialog.ConfirmDialog;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;
import retrofit2.Call;

public class BookingHomeFragment extends BaseFragment implements PtrHandler {

    private Context context;

    @BindView(R.id.pfl_root)
    PtrClassicFrameLayout pfl_root;

    @BindView(R.id.scrollView)
    ScrollView scrollView;

    //酒店名字
    @BindView(R.id.branchName)
    TextView branchName;
    @BindView(R.id.tv_topTitle)
    TextView tv_topTitle;
    @BindView(R.id.xzBName)
    TextView xzBName;

    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.phone)
    TextView phone;

    @BindView(R.id.numHour)
    TextView numHour;

    @BindView(R.id.convenientBanner)
    ConvenientBanner convenientBanner;
    private ArrayList<String> localImages = new ArrayList<String>();

    private String COORDSX, COORDSY;
    private String phoneTxt;

    private RoomAdapter roomAdapter;
    private RoomHourAdapter roomHourAdapter;
    @BindView(R.id.roomList)
    ListViewForScrollView roomList;
    @BindView(R.id.roomHourList)
    ListViewForScrollView roomHourList;

    private Calendar calendar;
    @BindView(R.id.numDate)
    TextView numDate;
    @BindView(R.id.startDate)
    TextView startDate;
    @BindView(R.id.endDate)
    TextView endDate;
    @BindView(R.id.rzStr)
    TextView rzStr;
    @BindView(R.id.ldStr)
    TextView ldStr;
    private String startDateStr;
    private String endDateStr;
    private String todatyDateStr;
    private int nunDateInt = 1;

    @BindView(R.id.collection)
    ImageView collection;
    private String TYPE;



    @Override
    protected int getLayout() {
        return R.layout.ui_booking_home;
    }

    @Override
    protected void onInit() {
        context = getActivity();
        calendar = Calendar.getInstance();
        pfl_root.setEnabledNextPtrAtOnce(true);
        pfl_root.setLastUpdateTimeRelateObject(this);
        pfl_root.setPtrHandler(this);
        pfl_root.setKeepHeaderWhenRefresh(true);
        pfl_root.disableWhenHorizontalMove(true);

        todatyDateStr = calendar.get(Calendar.YEAR) +"-"+ isOne(calendar.get(Calendar.MONTH)+1)+"-"+ isOne(calendar.get(Calendar.DAY_OF_MONTH))+"";

        startDate.setText( isOne(calendar.get(Calendar.MONTH)+1) + "-" + isOne(calendar.get(Calendar.DAY_OF_MONTH))+"");
        startDateStr = calendar.get(Calendar.YEAR) +"-"+ isOne(calendar.get(Calendar.MONTH)+1)+"-"+ isOne(calendar.get(Calendar.DAY_OF_MONTH))+"";


        if(calendar.get(Calendar.DAY_OF_MONTH) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH)){
            endDate.setText(isOne(calendar.get(Calendar.MONTH)+2)+"-"+ isOne(calendar.get(Calendar.DAY_OF_MONTH))+"");
            endDateStr = calendar.get(Calendar.YEAR) +"-"+ isOne(calendar.get(Calendar.MONTH)+2)+"-"+ isOne(calendar.get(Calendar.DAY_OF_MONTH))+"";
        }else{
            endDate.setText(isOne(calendar.get(Calendar.MONTH)+1)+"-"+ isOne(calendar.get(Calendar.DAY_OF_MONTH)+1)+"");
            endDateStr = calendar.get(Calendar.YEAR) +"-"+ isOne(calendar.get(Calendar.MONTH)+1)+"-"+ isOne(calendar.get(Calendar.DAY_OF_MONTH)+1)+"";
        }

        BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.startDateStr, startDateStr);
        BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.endDateStr, endDateStr);

        try {
            numDate.setText(ContextUtils.daysBetween(startDateStr , endDateStr) +"晚");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        hotel_info();
        queryBranch();

        roomList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                startActivity(new Intent(context, BookingRoomActivity.class).putExtra("id", decimalFormat.format(roomAdapter.getItem(i).get("id")))
                        .putExtra("startDateStr", startDateStr)
                        .putExtra("endDateStr", endDateStr)
                        .putExtra("surplus", decimalFormat.format(roomAdapter.getItem(i).get("surplus")))
                        .putExtra("IS_HOUR", "0"));

            }
        });

        roomHourList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                startActivity(new Intent(context, BookingRoomActivity.class).putExtra("id", decimalFormat.format(roomHourAdapter.getItem(i).get("id")))
                        .putExtra("startDateStr", startDateStr)
                        .putExtra("endDateStr", endDateStr)
                        .putExtra("surplus", decimalFormat.format(roomHourAdapter.getItem(i).get("surplus")))
                        .putExtra("IS_HOUR", "1"));

            }
        });
    }

    @Override
    public void fetchData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        getMbUserInfo();
    }

    private void hotel_info() {
        Call<ResultObjectModel> call01 = HttpAdapter.getSerives().hotel_info(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.HOTEL_ID));
        call01.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    LinkedTreeMap cfg_hotel = (LinkedTreeMap) linkedTreeMap.get("cfg_hotel");

                    branchName.setText(linkedTreeMap.get("branch_name")+"");
                    tv_topTitle.setText(linkedTreeMap.get("branch_name")+"");
                    xzBName.setText("选择"+linkedTreeMap.get("branch_name")+"");
                    address.setText("地址："+linkedTreeMap.get("branch_addr")+"");

                    if (linkedTreeMap.containsKey("branch_phone")){
                        phoneTxt = linkedTreeMap.get("branch_phone") +"";
                        phone.setText("电话："+linkedTreeMap.get("branch_phone")+"");
                    }else{
                        phone.setText("电话：");
                    }

                    if((linkedTreeMap.get("branch_coords")+"").contains(",")){
                        COORDSY = (linkedTreeMap.get("branch_coords")+"").split(",")[1];
                        COORDSX = (linkedTreeMap.get("branch_coords")+"").split(",")[0];
                    }

                    localImages = new ArrayList<>();
                    if (linkedTreeMap.containsKey("img_url_one")){
                        localImages.add(HttpAdapter.HEAD_URL + "uploadFiles/titleImgs/branch/lossless/" +linkedTreeMap.get("img_url_one"));
                    }
                    if (linkedTreeMap.containsKey("img_url_two")){
                        localImages.add(HttpAdapter.HEAD_URL + "uploadFiles/titleImgs/branch/lossless/" +linkedTreeMap.get("img_url_two"));
                    }
                    if (linkedTreeMap.containsKey("img_url_three")){
                        localImages.add(HttpAdapter.HEAD_URL + "uploadFiles/titleImgs/branch/lossless/" +linkedTreeMap.get("img_url_three"));
                    }
                    if (linkedTreeMap.containsKey("img_url_four")){
                        localImages.add(HttpAdapter.HEAD_URL + "uploadFiles/titleImgs/branch/lossless/" +linkedTreeMap.get("img_url_four"));
                    }

                    convenientBanner.setPages(new CBViewHolderCreator() {
                        @Override
                        public Object createHolder() {
                            return new LocalImageHolderView();
                        }
                    },localImages)
                            //设置指示器是否可见
                            .setPointViewVisible(true)
                            //设置自动切换（同时设置了切换时间间隔）
                            .startTurning(3000)
                            //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                            .setPageIndicator(new int[]{R.mipmap.ic_page_indicator, R.mipmap.ic_page_indicator_focused})
                            //设置指示器的方向（左、中、右）
                            .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT)
                            //设置点击监听事件
                            //                .setOnItemClickListener(this)
                            //设置手动影响（设置了该项无法手动切换）
                            .setManualPageable(true);

                    if(cfg_hotel.containsKey("room_onlineMake_switch")){
                        if(decimalFormat.format(cfg_hotel.get("room_onlineMake_switch")).equals("1")){
                            if(cfg_hotel.containsKey("makeDay")){
                                if(decimalFormat.format(cfg_hotel.get("makeDay")).equals("1")){
                                    findViewById(R.id.ptfLay).setVisibility(View.VISIBLE);
                                }else{
                                    findViewById(R.id.ptfLay).setVisibility(View.GONE);
                                }
                            }
                            if(cfg_hotel.containsKey("makeHour")){
                                if(decimalFormat.format(cfg_hotel.get("makeHour")).equals("1")){
                                    findViewById(R.id.zdfLay).setVisibility(View.VISIBLE);
                                }else{
                                    findViewById(R.id.zdfLay).setVisibility(View.GONE);
                                }
                            }

                            if(cfg_hotel.containsKey("makeDay")&&cfg_hotel.containsKey("makeHour")){
                                if(decimalFormat.format(cfg_hotel.get("makeDay")).equals("0") &&  decimalFormat.format(cfg_hotel.get("makeHour")).equals("0")){
                                    findViewById(R.id.timeLay).setVisibility(View.GONE);
                                }
                            }else{
                                findViewById(R.id.timeLay).setVisibility(View.VISIBLE);
                            }
                        }else{
                            findViewById(R.id.ptfLay).setVisibility(View.GONE);
                            findViewById(R.id.zdfLay).setVisibility(View.GONE);
                            findViewById(R.id.timeLay).setVisibility(View.GONE);
                        }
                    }


                }
            }
        });
    }
    private void room_type(String ID_CARD) {
        Call<ResultObjectModel> call01 = HttpAdapter.getSerives().room_type(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.HOTEL_ID), startDateStr, endDateStr,"0", ID_CARD);
        call01.enqueue(new OnNoResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")) {
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    List<LinkedTreeMap> list = (List<LinkedTreeMap>) userModelBaseResultModel.getData();
                    roomAdapter = new RoomAdapter(context, list);
                    roomList.setAdapter(roomAdapter);
                    roomHourAdapter = new RoomHourAdapter(context, list);
                    roomHourList.setAdapter(roomHourAdapter);
                    numHour.setText("（"+list.size()+"）");
                }
            }
        });
    }
    @OnClick({R.id.collection, R.id.dh, R.id.call, R.id.infoLay, R.id.startDateLay, R.id.endDateLay})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.collection:
                if (TYPE.equals("")){
                    final ConfirmDialog confirmDialog = new ConfirmDialog(context, "确定关注吗？", 1);
                    confirmDialog.show();
                    confirmDialog.setCanceledOnTouchOutside(false);
                    confirmDialog.setClicklistener(new ConfirmDialog.ClickListenerInterface() {
                        @Override
                        public void doConfirm() {
                            confirmDialog.dismiss();
                            addAttention();
                        }

                        @Override
                        public void doCancel() {
                            confirmDialog.dismiss();
                        }
                    });
                }else{
                    final ConfirmDialog confirmDialog = new ConfirmDialog(context, "确定取消关注吗？", 1);
                    confirmDialog.show();
                    confirmDialog.setCanceledOnTouchOutside(false);
                    confirmDialog.setClicklistener(new ConfirmDialog.ClickListenerInterface() {
                        @Override
                        public void doConfirm() {
                            confirmDialog.dismiss();
                            delAttention();
                        }

                        @Override
                        public void doCancel() {
                            confirmDialog.dismiss();
                        }
                    });
                }
                break;
            case R.id.endDateLay:
                DatePickerDialog datePicker01=new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear,
                                          int dayOfMonth) {
                        // TODO Auto-generated method stub
                        endDate.setText(isOne(monthOfYear+1)+"-"+ isOne(dayOfMonth)+"");
                        endDateStr = year+"-"+ isOne(monthOfYear+1)+"-"+ isOne(dayOfMonth)+"";
                        try {
                            numDate.setText(ContextUtils.daysBetween(startDateStr , endDateStr) +"晚");
                            nunDateInt = ContextUtils.daysBetween(startDateStr , endDateStr);
                            BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.endDateStr, endDateStr);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        getMbUserInfo();
                    }
                },  calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),  calendar.get(Calendar.DAY_OF_MONTH));
                datePicker01.show();
                break;
            case R.id.startDateLay:
                DatePickerDialog datePicker02=new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear,
                                          int dayOfMonth) {
                        // TODO Auto-generated method stub
                        startDate.setText(isOne(monthOfYear+1)+"-"+ isOne(dayOfMonth)+"");
                        startDateStr = year+"-"+ isOne(monthOfYear+1)+"-"+ isOne(dayOfMonth)+"";
                        try {
                            endDateStr =  ContextUtils.daysAdd(startDateStr, nunDateInt);
                            endDate.setText(ContextUtils.daysAdd(startDateStr, nunDateInt).substring(5));
                            BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.startDateStr, startDateStr);
                            BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.endDateStr, endDateStr);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        getMbUserInfo();
                    }
                },  calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),  calendar.get(Calendar.DAY_OF_MONTH));
                datePicker02.show();
                break;
            case R.id.infoLay:
                launch(BookingInfoActivity.class);
                break;
            case R.id.dh:
                if (TextUtils.isEmpty(COORDSX)){
                    Uri uri = Uri.parse("amapuri://route/plan/?dlat="+""+"&dlon="+""+"&dname="+branchName.getText().toString()+"&dev=0&t=0");
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                }else{
                    startActivity(new Intent(context, MapDialogAtivity.class).putExtra("COORDSX", COORDSX).putExtra("COORDSY", COORDSY));
                }
                break;
            case R.id.call:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    if (ContextCompat.checkSelfPermission(context,
                            Manifest.permission.CALL_PHONE)
                            != PackageManager.PERMISSION_GRANTED) {
                        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CALL_PHONE}, 10);
                    }else{
                        Intent intent =new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phoneTxt));
                        startActivity(intent);
                    }
                }else{
                    Intent intent =new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneTxt));
                    startActivity(intent);
                }
                break;
        }
    }

    private void getMbUserInfo() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().getMbUserInfo(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    room_type(""+linkedTreeMap.get("ID_CARD"));
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            }
        });
    }

    //为了方便改写，来实现复杂布局的切换
    private class LocalImageHolderView implements Holder<String> {
        private ImageView imageView;

        @Override
        public View createView(Context context) {
            //你可以通过layout文件来创建，不一定是Image，任何控件都可以进行翻页
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, String data) {
            Glide.with(context).load(data).placeholder(R.mipmap.detail_wait).error(R.mipmap.detail_error).into(imageView);
        }
    }


    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
        return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
    }

    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        hotel_info();
        getMbUserInfo();
        queryBranch();
        pfl_root.refreshComplete();
    }

    private void queryBranch() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().queryBranch(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.HOTEL_ID));
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();


                    if ((linkedTreeMap.get("TYPE")+"").equals("null")){
                        TYPE = "";
                        collection.setImageResource(R.mipmap.attention_status1);
                    }else{
                        TYPE = "1";
                        collection.setImageResource(R.mipmap.attention_status2);
                    }


                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }


    private String isOne(int num){
        if (num<10){
            return "0"+num;
        }else{
            return num+"";
        }
    }

    private void addAttention() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().addAttention(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN),  BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.HOTEL_ID));
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    ToastUtils.toastShort("关注成功！");
                    queryBranch();
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }

    private void delAttention() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().delAttention(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN),  BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.HOTEL_ID));
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    ToastUtils.toastShort("取消关注成功！");
                    queryBranch();
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }
}
